#include "../include/ArrayOps.h"

template<typename T>
void Array<T>::testArray() {
    cout << "=== 数组操作测试 ===" << endl;
    
    Array<int> arr(5);
    
    arr.assign(0, 10);
    arr.assign(1, 20);
    arr.assign(2, 30);
    arr.assign(3, 40);
    arr.assign(4, 50);
    
    cout << "数组内容: ";
    arr.print();
    
    cout << "arr[2] = " << arr.value(2) << endl;
    cout << "数组大小: " << arr.getSize() << endl;
    cout << "数组容量: " << arr.getCapacity() << endl;
    
    cout << endl;
}

template<typename T>
void Array<T>::interactiveTest() {
    cout << "=== 数组操作交互式测试 ===" << endl;
    
    int capacity = Utils::getIntInput("请输入数组容量: ");
    Array<int> arr(capacity);
    
    while (true) {
        cout << "\n当前数组: ";
        arr.print();
        cout << "数组大小: " << arr.getSize() << endl;
        cout << "数组容量: " << arr.getCapacity() << endl;
        
        cout << "\n请选择操作：" << endl;
        cout << "1. 赋值 (Assign)" << endl;
        cout << "2. 取值 (Value)" << endl;
        cout << "3. 清空数组" << endl;
        cout << "0. 返回主菜单" << endl;

        int choice = Utils::getIntInput("请输入选择 (0-3): ");

        if (choice == 0) break;

        try {
            switch (choice) {
                case 1: {
                    int index = Utils::getIntInput("请输入索引位置: ");
                    int value = Utils::getIntInput("请输入要设置的值: ");
                    arr.assign(index, value);
                    cout << "赋值成功！" << endl;
                    break;
                }
                case 2: {
                    int index = Utils::getIntInput("请输入索引位置: ");
                    int value = arr.value(index);
                    cout << "arr[" << index << "] = " << value << endl;
                    break;
                }
                case 3: {
                    Array<int> newArr(capacity);
                    arr = newArr;
                    cout << "数组已清空！" << endl;
                    break;
                }
                default:
                    cout << "无效选择！" << endl;
            }
        } catch (const exception& e) {
            cout << "错误: " << e.what() << endl;
        }
    }
}

template class Array<int>;